<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

class AutogeneratorControllerXml_elements extends JControllerAdmin
{
    /**
     *
     * @var AutogeneratorModelXml_element 
     */
	public $oModelXml_element;

    public $oApplication;
    
	public function __construct($arConfig = array())
	{
		parent::__construct($arConfig);
		
		$this->oModelXml_element = $this->getModel();
        
        $this->oApplication = JFactory::getApplication();
	}

	public function getModel($strName = 'Xml_element', $strPrefix = 'AutogeneratorModel', $arConfig = array('ignore_request' => true))
	{
		return parent::getModel($strName, $strPrefix, $arConfig);
	}
    
    /**
	 * Removes an item.
	 *
	 * @return  void
	 *
	 * @since   12.2
	 */
	public function delete()
	{
		// Check for request forgeries
		JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));

		// Get items to remove from the request.
		$cid = $this->oApplication->input->get('cid', array(), 'array');
        
        $iXmlTypeId = $this->oApplication->input->getInt('iXmlTypeId');
        
		if (!is_array($cid) || count($cid) < 1)
		{
			JLog::add(JText::_($this->text_prefix . '_NO_ITEM_SELECTED'), JLog::WARNING, 'jerror');
		}
		else
		{
			// Make sure the item ids are integers
			jimport('joomla.utilities.arrayhelper');
			JArrayHelper::toInteger($cid);

			// Remove the items.
			if ($this->oModelXml_element->delete($cid))
			{
				$this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
			}
			else
			{
				$this->setMessage($this->oModelXml_element->getError());
			}
		}

		$this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . '&iXmlTypeId=' . $iXmlTypeId, false));
	}
}
